import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { TemplateVO, TemplateForm, TemplateQuery } from '@/api/goods/express/types';

/**
 * 查询模板列表
 * @param query
 * @returns {*}
 */

export const listTemplate = (query?: TemplateQuery): AxiosPromise<TemplateVO[]> => {
  return request({
    url: '/order/template/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询模板详细
 * @param id
 */
export const getTemplate = (id: any): AxiosPromise<TemplateVO> => {
  return request({
    url: '/order/template/' + id,
    method: 'get'
  });
};

/**
 * 查询模板详细
 */
export const getClassifyAllList = (query:any): AxiosPromise<TemplateVO> => {
  return request({
    url: '/order/template/allList',
    method: 'get',
    params: query
  });
};
/**
 * 通过类型查询默认模板
 */
export const findDefaultByType = (type:String)=> {
  return request({
    url: `/order/template/findDefaultByType/${type}`,
    method: 'get'
  });
};

/**
 * 新增模板
 * @param data
 */
export const addTemplate = (data: TemplateForm) => {
  return request({
    url: '/order/template',
    method: 'post',
    data: data
  });
};

/**
 * 修改模板
 * @param data
 */
export const updateTemplate = (data: TemplateForm) => {
  return request({
    url: '/order/template',
    method: 'put',
    data: data
  });
};

/**
 * 删除模板
 * @param id
 */
export const delTemplate = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/template/' + id,
    method: 'delete'
  });
};

/**
 * 状态修改
 * @param goodsTemplateId 客户端id
 * @param status 状态
 */
export function changeStatus(data: any) {
  return request({
    url: '/order/template/changeStatus',
    method: 'put',
    data: data
  });
}

export default {
  list:listTemplate,
  get:getTemplate,
  add:addTemplate,
  update:updateTemplate,
  del:delTemplate,
  getClassifyAllList:getClassifyAllList
}